package servlets;

import java.io.IOException;

import javax.persistence.EntityManager;
import javax.persistence.Persistence;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.entity.Island;
import model.entity.User;

/**
 * Servlet implementation class Teste
 */
@WebServlet("/Teste")
public class Teste extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Teste() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		EntityManager manager = Persistence.createEntityManagerFactory("Shout2Me").createEntityManager();
		Island i = new Island();
		
		User u1 = new User();
		User u2= new User();
		User u3 = new User();
		
		/*List<User> l = new ArrayList<User>();
		l.add(u1);
		l.add(u2);
		l.add(u3);*/
		
//		u1.addIsland(i);
//		u2.addIsland(i);
		
		//i.setUsers(l);
		
		
		manager.persist(i);
		
		manager.persist(u3);
		manager.persist(u2);
		manager.persist(u1);
		
		manager.getTransaction().begin();
		manager.getTransaction().commit();
		
		
		
		response.getWriter().print("mensgem");
	}

}
